home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / mus2v131.zip / PlyNext.cmd < prev    next >
OS/2 REXX Batch file  |  1996-02-08  |  3KB  |  111 lines

  1. /* ########################################################################
  2.  
  3.    This REXX script will communicate with a running Module Player that
  4.    support a Command Pipe.
  5.  
  6.    The Following commands are used
  7.       Query Song  -- Returns three lines, first is the file name, second is the
  8.                      index and third is the song title. They represent
  9.                      the currently playing song.
  10.       Play Next -- Plays the next song
  11.  
  12.    ########################################################################
  13. */
  14. '@echo off'                       /* Don't echo commands */
  15. say " Module Player Next Song Changer V1.0                                     Ethos"
  16.    call OpenPlayer
  17.    if Result <> 0 then do
  18.       say "Error" Error
  19.       return
  20.    end
  21.  
  22.    if CallPlayer("Query","Song","") <> 0 then do
  23.       say "Error" Error
  24.       return
  25.    end
  26.    Say "Currently Playing Song" Result.1 "'" || Result.3 || "'"
  27.  
  28.    if CallPlayer("Play","Next","") <> 0 then do
  29.       say "Error" Error
  30.       return
  31.    end
  32.    say "Playing Next Song"
  33. return
  34.  
  35. /* ########################################################################
  36.  
  37.    Function - CallPlayer
  38.    Eg - if (CallPlayer("Query","Song","") <> 0) then Error
  39.  
  40.    Description - This procedure sends a command message to the player.
  41.                  An error is returned if the player doesn't understand
  42.                  the message or something else is wrong.
  43.                    Result - A stem containing each line of the result
  44.                    Error - Global error code
  45.  
  46.    ########################################################################
  47. */
  48. CallPlayer: procedure expose Result. Player Error
  49.    parse arg Command, SCommand, Arg
  50.  
  51.    Error = ""
  52.    Result.0 = 0
  53.  
  54.    /* Player not loaded */
  55.    if (Player = "") then do
  56.       Error = "Player not Inited"
  57.       return 1
  58.    end
  59.  
  60.    call lineout Player,Command SCommand Arg
  61.  
  62.    /* Get all the results */
  63.    do while (1)
  64.       Line = linein(Player)
  65.  
  66.       /* Error or something */
  67.       if (pos("!!",Line) = 1) then do
  68.          if (Line = "!! OK") then
  69.             return 0
  70.          Error = substr(Line,4)
  71.          return 1
  72.       end;
  73.  
  74.       Result.0 = Result.0 + 1
  75.       I = Result.0
  76.       Result.I = Line
  77.    end
  78.  
  79. return 0
  80.  
  81. /* ########################################################################
  82.  
  83.    Function - OpenPlayer
  84.    Eg - call OpenPlayer
  85.  
  86.    Description - This procedure opens the pipe and sets the following:
  87.                    Player - The name of the pipe - \pipe\Player
  88.                    Version - The pipe comminication version
  89.                    Type - The program running on the other end, 'Text UI'
  90.                    Error - Global Error Code
  91.  
  92.    ########################################################################
  93. */
  94. OpenPlayer:procedure expose Player Version Type Error
  95.    Error = ""
  96.  
  97.    Result = Stream("\pipe\ModulePlayer","C","OPEN");
  98.    if (Result <> "READY:") then do
  99.       Error = "Unable to communicate with the  Player, is it running?"
  100.       Player = ""
  101.       return 1
  102.    end
  103.    Player = "\pipe\ModulePlayer"
  104.  
  105.    /* Get the version */
  106.    S = linein(Player)
  107.    parse var S 'V' Version .
  108.    Type = linein(Player)
  109. return 0
  110.  
  111.